package cn.wolfcode.luowowo.article.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 攻略明细
 */
@Setter
@Getter
@ToString
public class Question extends BaseDomain {

    public static final int STATE_NORMAL = 0;  //正常
    public static final int STATE_PUBLISH = 1; //发布

    private UserInfo author;

    private Destination dest;  //关联的目的地

    //private StrategyCatalog catalog;  //关联的分类

    private String title;  //标题

    private String content; //内容

    private Date createTime;  //创建时间

    private Date releaseTime;  //发布时间

    private Date lastUpdateTime;  //最后更改时间

    private int viewnum;  //点击数

    private int replynum;  //攻略评论数

    private int attentionnum; //收藏数

    private int thumbsupnum; //点赞个数

    private int state = STATE_NORMAL;  //状态

    private Answer oneAnswer;

    private List<Answer> allAnswer;

    private String tag;

    private List<String> tagList;

    public String getStateDisplay(){
        return state == STATE_PUBLISH ? "发布" :"正常";
    }

    //添加编辑时，前端传入是String集合， 数据库保存的是拼接的字符串
    /*public String getTag(){
        if(tagList!=null){
            return StringUtils.arrayToDelimitedString(new List[]{tagList},",");
        }
        return null;

    }*/
    //从数据库拿出的拼接字符串转换成集合
    public List<String> getTagList(){
        List<String> tags = new ArrayList<>();
        Long[] ids = null;
        if(StringUtils.hasLength(tag)){
            String[] strs = tag.split(",");
            for (String str : strs) {
                tags.add(str);
            }
        }
        return tags;
    }
   /* public Long[] getRefIds(){
        Long[] ids = null;
        if(StringUtils.hasLength(ref)){
            String[] strs = ref.split(",");
            ids = new Long[strs.length];
            for (int i = 0; i <strs.length ; i++) {
                ids[i] =  Long.parseLong(strs[i]);
            }
        }
        return ids;
    }*/
}